package other;

import java.util.LinkedList;
import java.util.List;
import java.util.Queue;

public class levelOrder_429 {
    public List<List<Integer>> levelOrder(Node root) {
        Queue<Node> queue = new LinkedList<>();
        List<List<Integer>> list = new LinkedList<>();
        if (root == null) {
            return list;
        }
        queue.add(root);
        while(!queue.isEmpty()){
            int size = queue.size();  //当前这一层节点个数
            List<Integer> temp = new LinkedList<>();
            for(int i = 0; i < size; i++){
                Node node = queue.poll();
                temp.add(node.val);
                for(Node child : node.children){
                    if (node!=null) queue.add(child);
                }
            }
            list.add(temp);
        }
        return list;
    }
}
